//
//  AddressBook.m
//  OC08_Category_Extension_Protocol
//
//  Created by Scott on 16/3/7.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "AddressBook.h"

/**
 * 类的延展 
 * 注意: 类名后面()内为空.
 * 声明私有化(隐藏)的属性和方法.
 */
@interface AddressBook ()

@property (nonatomic, retain) NSMutableDictionary *mDic;

@end

@implementation AddressBook

- (void)dealloc {
    
    [_mDic release];
    [super dealloc];
}

- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        self.mDic = [NSMutableDictionary dictionary];
        
    }
    return self;
}

- (void)addContact:(Contact *)contact {
    
    // 名字首字母大写
    NSString *group = [[contact.name substringToIndex:1] uppercaseString];
    
    NSMutableArray *arrOfCont = [self.mDic objectForKey:group];
    
    if (arrOfCont == nil) {
        
        arrOfCont = [NSMutableArray array];
        [arrOfCont addObject:contact];
        [self.mDic setObject:arrOfCont forKey:group];
    } else {
        [arrOfCont addObject:contact];
    }

    
}

@end
